<template>
  <view>
    <musicHead title="热歌榜" :icon="true"></musicHead>
    <view class="container">
      <scroll-view scroll-y="true">
        <view class="hot">
          <view class="index-list">
            <view
              class="index-list-item"
              v-for="(item, index) in topsList"
              :key="index"
              @tap="goToList(item.id)"
            >
              <view class="index-list-img">
                <image :src="item.coverImgUrl" mode="" />
                <text>{{ item.updateFrequency }}</text>
              </view>
              <view class="index-list-text">
                <view v-for="(mItem, index) in item.tracks" :key="index"
                  >{{ index + 1 }}.{{ mItem.first }}-{{ mItem.second }}</view
                >
              </view>
            </view>
          </view>
        </view>

        <view class="last-hot">
          <view class="last-list">
            <view
              class="last-list-item"
              v-for="(item, index) in topLastList"
              :key="index"
              @tap="goToList(item.id)"
            >
              <view class="last-list-img">
                <image :src="item.coverImgUrl" mode="" />
                <text>{{ item.updateFrequency }}</text>
              </view>
            </view>
          </view>
        </view>
      </scroll-view>
    </view>
  </view>
</template>

<script>
import { getTopList } from "@/api";
export default {
  components: {},

  data() {
    return {
      topsList: [],
      topLastList: [],
    };
  },
  onLoad(params) {
    this.gettopList();
  },
  methods: {
    async gettopList() {
      try {
        let result = await getTopList();
        this.topLastList = result.list.slice(5, result.list.length - 1);
        console.log(this.topLastList);
        result.list.length = 4;
        this.topsList = result.list;
        console.log(this.topsList);
      } catch (error) {}
    },
    goToList(id) {
      uni.navigateTo({
        url: `/pages/list/index?id=${id}`,
      });
    },
  },
};
</script>

<style lang='less' scoped>
.hot {
  display: flex;
  flex-wrap: wrap;
  margin: 30rpx 30rpx;
  // background-color: yellow;
  .hot-title {
    display: flex;
    justify-content: space-between;
    width: 100%;
    align-items: center;
    & > view:nth-child(-n + 2) {
      font-size: 48rpx;
      font-weight: 900;
      color: red;
    }

    & > view:nth-child(2) {
      color: #000000;
      font-size: 42rpx;
      margin-left: 20rpx;
    }

    & > view:nth-child(3) {
      // border: 1px solid rgb(185, 185, 185);
      padding: 0rpx 10rpx;
      background-color: #ffffff;
      // border-radius: 30rpx;
      margin-left: auto;
      color: #999999;
      font-size: 26rpx;
    }
  }

  .index-list {
    margin-top: 20rpx;
    .index-list-item {
      display: flex;
      margin-bottom: 34rpx;
      .index-list-img {
        position: relative;
        width: 212rpx;
        height: 212rpx;
        border-radius: 30rpx;
        overflow: hidden;
        margin-right: 22rpx;
        image {
          width: 100%;
          height: 100%;
        }

        text {
          position: absolute;
          left: 12rpx;
          bottom: 16rpx;
          color: white;
          font-size: 20rpx;
        }
      }
      .index-list-text {
        display: flex;
        flex: 1;
        flex-direction: column;
        justify-content: space-around;
        line-height: 66rpx;
        font-size: 26rpx;
        view {
          text-overflow: -o-ellipsis-lastline;
          overflow: hidden;
          // text-overflow: clip;
          display: -webkit-box;
          -webkit-line-clamp: 1;
          line-clamp: 1;
          -webkit-box-orient: vertical;
        }
      }
    }
  }
}

.last-hot {
  margin: 0 20rpx;
  .last-list {
    margin-top: 20rpx;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;

    .last-list-item {
      margin-bottom: 34rpx;
      width: 214rpx;
      height: 214rpx;
      border-radius: 30rpx;
      overflow: hidden;
      margin-right: 22rpx;
      .last-list-img {
        position: relative;
        width: 212rpx;
        height: 212rpx;
        border-radius: 30rpx;
        overflow: hidden;
        margin-right: 22rpx;
        image {
          width: 100%;
          height: 100%;
        }

        text {
          position: absolute;
          left: 12rpx;
          bottom: 16rpx;
          color: white;
          font-size: 20rpx;
        }
      }
      image {
        width: 100%;
        height: 100%;
      }
      text {
        position: absolute;
        left: 12rpx;
        bottom: 16rpx;
        color: white;
        font-size: 20rpx;
      }
    }
  }
}
</style>